package com.example.chasshelper;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.example.chasshelper.dao.ClassroomDao;
import com.example.chasshelper.dao.CourseDao;
import com.example.chasshelper.dao.MessageDao;
import com.example.chasshelper.dao.RegistrationDao;
import com.example.chasshelper.dao.SolutionDao;
import com.example.chasshelper.dao.StudentDao;
import com.example.chasshelper.dao.TeacherDao;
import com.example.chasshelper.dao.TestDao;
import com.example.chasshelper.utils.DaoUtils;

public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {
    private static final String TAG = RegisterActivity.class.getSimpleName();
    private final Activity mContext = RegisterActivity.this;
    //控件
    private ImageView iv_header;
    private EditText et_userAccount;
    private EditText et_userPassword;
    private EditText et_check_userPassword;
    private EditText et_phone;
    private EditText et_userName;
    private RadioGroup rg_identity;
    private EditText et_age;
    private RadioGroup rg_sex;
    private EditText et_school;
    private EditText et_major;
    private EditText et_userClass;
    private Button btn_back;
    private Button btn_register;

    private RadioButton rb_current;
    //dao
    private TeacherDao teacherDao= DaoUtils.getTeacherDao();
    private StudentDao studentDao=DaoUtils.getStudentDao();
    private CourseDao courseDao=DaoUtils.getCourseDao();
    private ClassroomDao classroomDao=DaoUtils.getClassroomDao();
    private RegistrationDao registrationDao=DaoUtils.getRegistrationDao();
    private SolutionDao solutionDao = DaoUtils.getSolutionDao();
    private MessageDao messageDao = DaoUtils.getMessageDao();
    private TestDao testDao = DaoUtils.getTestDao();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        //初始化界面
        initUI();
        //初始化数据
        initData();
    }

    private void initUI() {
        //绑定控件
        iv_header = findViewById(R.id.iv_header);
        et_userAccount = findViewById(R.id.et_userAccount);
        et_userPassword = findViewById(R.id.et_userPassword);
        et_check_userPassword = findViewById(R.id.et_check_userPassword);
        et_phone = findViewById(R.id.et_phone);
        et_userName = findViewById(R.id.et_userName);
        rg_identity = findViewById(R.id.rg_identity);
        et_age = findViewById(R.id.et_age);
        rg_sex = findViewById(R.id.rg_sex);
        et_school = findViewById(R.id.et_school);
        et_major = findViewById(R.id.et_major);
        et_userClass = findViewById(R.id.et_userClass);
        btn_back = findViewById(R.id.btn_back);
        btn_register = findViewById(R.id.btn_register);
        //点击事件
        btn_back.setOnClickListener(this);
        btn_register.setOnClickListener(this);
    }

    private void initData() {
        //dao实例化

        //adapter实例化
    }

    @Override
    public void onClick(View view) {
        Intent intent = new Intent();
        String userAccount = et_userAccount.getText().toString();
        String userPassword = et_userPassword.getText().toString();
        String check_userPassword = et_check_userPassword.getText().toString();
        String phone = et_phone.getText().toString();
        String userName = et_userName.getText().toString();
        String identity ="未选中";
        if (rg_identity.getCheckedRadioButtonId() != -1) {
            rb_current = findViewById(rg_identity.getCheckedRadioButtonId());
            identity = rb_current.getText().toString();

        }
        String age = et_age.getText().toString();
        String sex = "未选中";
        if (rg_sex.getCheckedRadioButtonId() != -1) {
            rb_current = findViewById(rg_sex.getCheckedRadioButtonId());
            sex = rb_current.getText().toString();
        }
        String school = et_school.getText().toString();
        String major = et_major.getText().toString();
        String userClass = et_userClass.getText().toString();
        //测试
        System.out.println("账号："+userAccount+"，密码："+userPassword+"，确认密码："+check_userPassword+"，手机号："+phone+"，用户名："
                +userName+"，身份："+identity+"，年龄："+age+"，性别："+sex+"，学校："+school+"，专业："+major+"，班级："+userClass);
        switch (view.getId()) {
            case R.id.btn_back://返回上一页
                finish();
                break;
            case R.id.btn_register://注册，成功则返回上一页
                finish();
                break;
        }

    }

}